﻿using Abp.EntityFramework;
using Laboratory.Entities.User;
using Laboratory.EntityFramework;
using Laboratory.EntityFramework.Repositories;
using Laboratory.IRepositories.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace Laboratory.Repositories.User
{
    public class MenuRepository : LaboratoryRepositoryBase<Menu, Guid>, IMenuRepository
    {
        public MenuRepository(IDbContextProvider<LaboratoryDbContext> dbContextProvider) : base(dbContextProvider)
        {

        }

        /// <summary>
        /// 验证显示名称是否存在
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="displayName">显示名称</param>
        /// <param name="parentId">父级Id</param>
        /// <returns></returns>
        public bool ExistsDisplayName(Guid? id, string displayName, Guid? parentId)
        {
            Expression<Func<Menu, bool>> condition =
                x => (id == null || x.Id != id) &&
                x.DisplayName == displayName &&
                x.ParentId == parentId;

            Menu menu = this.FirstOrDefault(condition);

            return menu != null;
        }


    }
}
